package cn.livingCloud.controller.core.validator;

import cn.livingCloud.dto.CaseFinishFormDto;
import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

/**
 * Created by DingJie on 2016/6/7.
 */
@Component
public class CaseFinishFormDtoValidator implements Validator {
    @Override
    public boolean supports(Class<?> aClass) {
        return CaseFinishFormDto.class.equals(aClass);
    }

    @Override
    public void validate(Object o, Errors errors) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "caseUuid", null, "参数错误");
        CaseFinishFormDto formDto = (CaseFinishFormDto) o;
        validateImage(formDto, errors);
    }

    private void validateImage(CaseFinishFormDto formDto, Errors errors) {
        if (formDto.getImageList().size() < 1) {
            errors.rejectValue("imageList", null, "案件图片至少传一张");
        }
    }
}
